from backend.cews.models import StockItem, StockItemRelation

def all_related_stock_code_by_stock_item(stock_item:StockItem):
    
    rels = StockItemRelation.objects.filter(parent=stock_item)
    
    scs = [stock_item.stock_code]
    
    for rel in rels:
        scs.append(rel.child.stock_code)
    
    return scs
   
def all_related_stock_code_by_stock_code(stock_code:str):
    stock_item = StockItem.objects.get(stock_code=stock_code)
    return all_related_stock_code_by_stock_item(stock_item)
    
    